import gcRequest from '..'
import {
  commentsRes,
  createCommentReplyRes,
  createCommentRes,
  replysRes
} from './types'
export const getComments = (
  articleId: number,
  { offect, limit }: { offect: number; limit: number }
) => {
  return gcRequest.get<commentsRes.RootObject>({
    url: `/comment/article/${articleId}`,
    params: {
      offect,
      limit
    }
  })
}

export const createComment = (articleId: number, content: string) => {
  return gcRequest.post<createCommentRes.RootObject>({
    url: '/comment',
    data: {
      articleId,
      content
    }
  })
}

export const createCommentReply = (
  commentId: number,
  content: string,
  replyId: number | null,
  toUserId: number
) => {
  return gcRequest.post<createCommentReplyRes.RootObject>({
    url: '/comment/reply',
    data: {
      commentId,
      replyId,
      content,
      toUserId
    }
  })
}

export const getReplys = (
  commentId: number,
  { offect, limit }: { offect: number; limit: number }
) => {
  return gcRequest.get<replysRes.RootObject>({
    url: `/comment/${commentId}`,
    params: {
      offect,
      limit
    }
  })
}
